package com.msh.platform.elm.dao;

import com.msh.platform.elm.entity.SaleInfo;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface SaleInfoRepository extends JpaRepository<SaleInfo,Integer> {
    
    @Query(value="select s from  SaleInfo s where pubNoId = ?1 and ((dqId in(select id from SaleDq where type = 'week' and dq like %?2%) or dqId in(select id from SaleDq where type = 'month' and dq like %?3%) or dqId in(select id from SaleDq where type = 'day'))"
    		+ " and dqId not in(select dqId from SaleDqOpt where delDay like %?4%)"
    		+ " or dqId in(select dqId from SaleDqOpt where addDay like %?4%))")
    List<SaleInfo> findDqSale(int pubNoId,int weekValue,int dayValue,String dqStr);
    
    List<SaleInfo> findByPubNoId(int pubNoId);
    
    @Modifying
    @Transactional
    @Query("delete from SaleInfo s where s.pubNoId = ?1")
    void deleteByPubNoId(String pubNoId);
}
